package org.bluedream.core.module.service.goods;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.commons.collections.map.HashedMap;
import org.bluedream.comm.base.BaseServiceImpl;
import org.bluedream.comm.utils.EmptyUtil;
import org.bluedream.core.module.dao.goods.BrandItemDao;
import org.bluedream.core.module.entity.goods.BrandItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Map;

/**
 * @ClassName BrandItemService
 * @Description TODO
 * @Author foxsand
 * @Data 2021-07-26 9:34
 * @Version
 */
@Service
@DS("master")
public class BrandItemService extends BaseServiceImpl<BrandItemDao, BrandItem> implements IService<BrandItem> {
    private static final Logger logger = LoggerFactory.getLogger(BrandItemService.class);

    @Override
    public BrandItem getById(Serializable id) {
        if (EmptyUtil.isEmpty(id)){
            return new BrandItem();
        }
        return super.getById(id);
    }

    public IPage<BrandItem> findPage(BrandItem entity, String... args) {
        Map<String , Object> search = new HashedMap();
        if (EmptyUtil.isNoEmpty(entity.getCode())
                || EmptyUtil.isNoEmpty(entity.getName())
        ){
            if (EmptyUtil.isNoEmpty(entity.getCode())){
                search.put("code" , entity.getCode());
            }
            if (EmptyUtil.isNoEmpty(entity.getName())){
                search.put("name" , entity.getName());
            }
        }else {
            long limit = entity.getLimit();
            long page = entity.getPage();
            entity = new BrandItem();
            entity.setLimit(limit);
            entity.setPage(page);
        }
        return super.findPage(entity , search , args);
    }
}
